package ly.gupao.edu.java8.Topic12;

import java.time.*;
import java.time.temporal.*;

/**
 * @author: liyang
 * @date：2018/11/15 0015
 * describe：
 */
public class DateTest {

    public static void main(String[] args) {
        LocalDate date = LocalDate.now().plus(1, ChronoUnit.DAYS);
        date = date.with(getAjduster());
        System.out.println(date);
    }

    /**
     * 请设计一个 NextWorkingDay 类，该类实现了 TemporalAdjuster 接口，能够计算明天
     * 的日期，同时过滤掉周六和周日这些节假日。格式如下所示：
     * date = date.with(new NextWorkingDay());
     * 如果当天的星期介于周一至周五之间，日期向后移动一天；如果当天是周六或者周日，则
     * 返回下一个周一
     */
    public static TemporalAdjuster getAjduster(){
        TemporalAdjuster adjuster = TemporalAdjusters.ofDateAdjuster( temporal -> {
            DayOfWeek dow = DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK));
            int dayOfAdd = 1;
            if(dow == DayOfWeek.FRIDAY) dayOfAdd = 3;
            else if(dow == DayOfWeek.SATURDAY) dayOfAdd = 2;
            return temporal.plus(dayOfAdd, ChronoUnit.DAYS);
        });
        return adjuster;
    }

}
